<?php
global $badgeforms;

$img_path = drupal_get_path('module', 'badgesystem') . '/images/lancer/';

foreach ( $badgeforms as $key => $badge ):
	if ( $badge['public'] || user_is_logged_in() ):

		$percent = $progress[$key] / $badgeforms[$key]['complete'];

		if ( $progress[$key] >= $badgeforms[$key]['complete'] ) {
			$badge_img = $img_path . $key . '-small-complete.png';
		} else {
			$badge_img = $img_path . $key . '-small.png';
		}
?>
	<div class="single-badge-wrapper badge-<?php echo $key; ?> <?php if ( $progress[$key] >= $badgeforms[$key]['complete'] ) echo 'badge-complete'; ?>">
		<div class="badge-image badge-image-small">
			<?php if ( $editable ): ?><a href="/user/<?php echo $uid; ?>/badges/<?php echo $key; ?>"><?php endif; ?>
			<img src="/<?php echo $img_path; ?>empty-small.png" class="badge-empty" alt="<?php echo $badge['title']; ?> Badge: <?php echo (int)($percent * 100); ?>% Complete" />
			<div class="badge-progress" style="height: <?php echo ceil($percent * 64); ?>px; background-image: url(/<?php echo $badge_img; ?>);">&nbsp;</div>
			<?php if ( $editable ): ?></a><?php endif; ?>
		</div>
		<p class="badge-title">
			<?php if ( $editable ): ?><a href="/user/<?php echo $uid; ?>/badges/<?php echo $key; ?>"><?php endif; ?>
			<?php echo $badge['title']; ?>
			<?php if ( $editable ): ?></a><?php endif; ?>
		</p>
	</div>
	<?php endif; ?>
<?php endforeach; ?>
